package com.qf.boot2203.controller;

import com.baomidou.kaptcha.Kaptcha;
import com.qf.boot2203.service.UserService;
import com.qf.boot2203.vo.ResultVo;
import com.qf.boot2203.vo.UserRegistVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("/user")
public class RegisterUser {

    @Autowired
    Kaptcha kaptcha;

    @Autowired
    UserService userService;

    @PostMapping("/regist")
    public ResultVo register(UserRegistVo userRegistVo) throws IOException {

        //0. 打日志
        log.debug("入参，userRegistVo={}", userRegistVo);

        //1.验证验证码是否正确
        kaptcha.validate(userRegistVo.getCaptchar());

        //2. 验证正确，处理用户注册的业务逻辑
        userService.registUser(userRegistVo);

        return ResultVo.ok();
    }
}
